package cn.sxt.yxl.users.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.sxt.yxl.users.dao.IARoleDao;
import cn.sxt.yxl.users.pojo.ARole;
import cn.sxt.yxl.users.service.IARoleService;

@Service("roleService")
public class ARoleServiceImpl implements IARoleService{

	@Resource
	private IARoleDao roleDao;
	//查询单个管理员
	@Override
	public ARole findOne(Map<String, Object> map) {
		
		return roleDao.findOne(map);
	}
	
	//添加管理员
	@Override
	public JSONObject saveOne(ARole role) {
		
		int res = roleDao.saveOne(role);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}
	@Override
	public JSONObject updateOne(ARole role) {
		int res = roleDao.updateOne(role);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}
	@Override
	public JSONObject deleteOne(ARole role) {
		int res = roleDao.deleteOne(role);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}

	
}
